package com.sun.login;

import android.os.Bundle;
import android.text.TextUtils;
import android.widget.Button;
import android.widget.EditText;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.sun.lib.base.BaseMvpActivity;
import com.sun.lib.base.basemvp.Presenter;
import com.sun.lib.constant.ConstantArouter;
import com.sun.lib.factory.ServiceFactory;
import com.sun.lib.inject.InjectPresenter;
import com.sun.lib.service.ILoginService;
import com.sun.login.mvpview.LoginContract;
import com.sun.login.presenter.LoginPresenter;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

@Route(path = ConstantArouter.PATH_LOGIN_ACTIVITY)
public class LoginActivity extends BaseMvpActivity<LoginContract.LoginImpl> implements LoginContract.LoginMvpView {

    @BindView(R2.id.numView)
    EditText numView;
    @BindView(R2.id.pwdView)
    EditText pwdView;
    @BindView(R2.id.loginView)
    Button loginView;

    @InjectPresenter
    private LoginPresenter loginPresenter;

    @Override
    protected void initialize(Bundle savedInstanceState) {
       /* LoginPresenter loginPresenter = new LoginPresenter();
        loginPresenter.attachView(this);*/
    }

    @Override
    protected int getLayoutResID() {
        return R.layout.activity_login;
    }

    @OnClick(R2.id.loginView)
    public void onViewClicked() {
        String tel = numView.getText().toString().trim();
        String pwd = pwdView.getText().toString().trim();
        if (TextUtils.isEmpty(tel)) {
            showToast("请输入手机号");
            return;
        }
        if (TextUtils.isEmpty(pwd)) {
            showToast("请输入密码");
            return;
        }
        loginPresenter.login();
        if (tel.equals("18501993540") && pwd.equals("123456")) {
            LoginManager.getInstance().saveLoginInfo(tel, pwd);
            LoginHelper.loginSuccess();
            //showToast("登录成功!");
            finish();
        } else {
            showToast("手机号或密码错误!");
        }
    }

    @Override
    public void loginSuccess() {

    }

    @Override
    protected LoginContract.LoginImpl createPresenter() {
        return null;
    }
}
